package com.lh.project.controller;

import com.lh.project.common.BaseResponse;
import com.lh.project.common.ResultUtils;
import com.lh.project.model.entity.Voucher;
import com.lh.project.service.VoucherService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/voucher")
public class VoucherController {
    @Resource
    private VoucherService voucherService;

    @GetMapping("/get")
    public BaseResponse<List<Voucher>> getVoucherByFoodId(@RequestParam Long foodId){
        List<Voucher> voucherList = voucherService.getVoucherByFoodId(foodId);
        return ResultUtils.success(voucherList);
    }

    /**
     * 新增普通券
     * @param voucher 优惠券信息
     * @return 优惠券id
     */
    @PostMapping
    public BaseResponse<String> addVoucher(@RequestBody Voucher voucher) {
        voucherService.save(voucher);
        return ResultUtils.success("添加成功");
    }

    /**
     * 新增秒杀券
     * @param voucher 优惠券信息，包含秒杀信息
     * @return 优惠券id
     */
    @PostMapping("seckill")
    public BaseResponse<Voucher> addSeckillVoucher(@RequestBody Voucher voucher) {
        voucherService.addSeckillVoucher(voucher);
        return ResultUtils.success(voucher);
    }
}
